package algorithms.leecode;

public class Au63 {
    public static void main(String[] args) {
        System.err.println(new Au63().uniquePathsWithObstacles(new int[][]
                        {{1,0,0},
                        {0,0,0}}));
    }
    public int uniquePathsWithObstacles(int[][] obstacleGrid) {
        int len = obstacleGrid.length;
        int len1 = obstacleGrid[0].length;
        int[] zc = new int[len];
        int[] zf = new int[len];
        for (int i = 0; i < len1; i++) {
            for (int j = 0; j < len; j++) {
                int x = len1 - i - 1;
                int y = len - j - 1;
                if (obstacleGrid[y][x] == 1) {
                    zc[j] = 0;
                } else {
                    if (j == 0) {
                        if (i == 0) {
                            zc[j] = 1;
                        } else {
                            zc[j] = zf[j];
                        }
                    } else {
                        zc[j] = zc[j - 1] + zf[j];
                    }
                }
            }
            zf = zc;
            zc = new int[len];
        }
        return zf[len - 1];
    }
}
